package com.cloud.mall.test.controller;

import com.cloud.mall.dto.test.Order;
import com.cloud.mall.result.GeneralResponse;
import com.cloud.mall.test.service.OrderService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: 梁二东
 * @Date: 2024/12/15 11:26
 * @Description:
 **/
@RestController
@RequestMapping("/testorder")
public class OrderController {

    @Resource
    private OrderService orderService;

    // 模拟创建订单
    @GetMapping("/createOrder")
    public GeneralResponse<Order> createOrder(@RequestParam("userId") String userId,
                                              @RequestParam("commodityCode") String commodityCode,
                                              @RequestParam("orderCount") Integer orderCount) {
        return GeneralResponse.success(orderService.create(userId, commodityCode, orderCount));
    }

    // 查询顶顶那
    @GetMapping("/getOrderById")
    public GeneralResponse<Order> getOrderById(@RequestParam("id") Integer id) {
        return GeneralResponse.success(orderService.getOrderById(id));
    }
}
